At a high-level, queries operate on collections rather than individual documents. Filter, search, and retrieve specific information based on various criteria using Boolean operators, equal and unequal operators, comparison operators, and match operators.
"isDeleted"
boolean property set to "true"
:
"isDeleted"
boolean property set to "false"
:
==
.
For example, to find documents that have a title equal to "Harry Potter"
:
!=
.
For example, to find documents that are not of the title “Lord of the Rings”:
age
field property is less than or equal to the value of 18
:
age
field property is less than the value of 18
:
age
field property is greater than or equal to the value of 18
:
age
field property is greater than the value of 18
:
SQL | Ditto |
---|---|
AND | && |
OR | || |
NOT | ! |
contains( ) | contains( ) |
AND
statements, use &&
for a condition that evaluates to true only when all of its conditions are set to true
.
For example, to find documents that have a theme
field property equal to "Dark"
and a name field property equal to "Light"
:
OR
statements, use ||
for a logical or predicate statement.
For example, to find documents that are "Tom"
or "Arthur"
:
NOT
statements, use !
for logical not predicate statements:
For example, find documents that are neither “Hamilton” nor “Morten”:
starts_with(property, test)
to test if a field property with a string value starts with a test string.
For example, to find documents with a title
field property that begins with "Lord"
:
ends_with(property, test)
to test if a field property with a string value ends with a test string.
For example, to find documents with a title
field property that ends with "Rings"
:
regex(property, test)
to see if a field property with a string value passes a regular expression. For more information, see the official Mozilla Developer Network Docs (MDN) > Regular Expressions.
For example, to find documents containing only upper and lowercase letters, numbers, and underscores:
null
to check for the existence of a value of a given field.
For example, to find documents with a color
field property that has no value:
map
structure. If necessary, use an array
.
The array
type in Ditto is a CRDT and behaves differently than the primitive array
type. For more information, see the Platform Manual Data Types.
arrays
in Ditto.Due to potential merge conflicts when offline peers reconnect to the mesh and attempt to sync their updates, especially when multiple peers make concurrent updates to the same item within the array
.Operator | Operation |
---|---|
contains(array, value) | Checks for value in the array |
a[0][1]["_123"]
a["0"]["1"]
[”a”][”0”][”1”]
$foo
($ isn’t a valid character anywhere in the unquoted string)a[1st]
(1st isn’t a valid unquoted string for field access, as the first character is a number)b[2nd]
(same reason as above)b[$foo]
($ isn’t a valid character anywhere in the unquoted string)b[foo$]
(same reason as above)a["foo"]b
(missing [""] around b)["$foo"]
a["1st"]
b["2nd"]
b["$foo"]
b["foo$"]
b["foo"]["b"]